﻿@model IList<FCDB.Entity.FormAttachment>

<div id="divFormAttachment"> 
  @if (string.IsNullOrEmpty(Request["ViewDetail"]))
        {
         <p style="display:block; height: 28px;">
   <button type="button" onclick="AddFormAttachment()" id="btnAddFormAttachment" class="fj btn_c3 btn_s" >添加附件</button>
   <button type="button" id="btnDelFormAttachment" onclick="DelFormAttachment()" class="fj btn_c3 btn_s" >刪除</button>
		</p>
     }
     
    else if(Request["ViewDetail"]=="2")
    {
         <p style="display:block; height: 28px;">
           <button type="button" onclick="AddFormAttachment()"class="fj btn_c3 btn_s"    >添加附件</button>
         <button type="button"  onclick="DelFormAttachment()" class="fj btn_c3 btn_s"    disabled="disabled">刪除</button>
             </p>
    } else
    {
        <p class="yj_tit">附件列表</p>
    }

</div> 
<div>
   <table id="tbFormAttachment">
       @{
          var CurrentActivityGuid=ViewBag.CurrentActivityGuid;
          
       foreach (var item in Model)
       {
           <tr>
               <td>
                   <input   @((item.FormType!=""&&item.FormID==0)||(CurrentActivityGuid==""||CurrentActivityGuid==null)?"":"disabled='disabled'") 
                        class="ckAttachment" name="ck" type="checkbox" value="@item.ID" />
               </td>
               <td>
                   <p>
                       @if (item.AttachmentType == 1)
                       {
                       　<a     href="javascript:getAttachment('@Url.Action("GetFormAttachementFile", "Form", new { FileName = item.Attachment })')" >@item.Name</a>
                       }
                       else
                       {
                          <a href="javascript:getAttachment('@item.Attachment')">@item.Name</a>
                       }
                   </p>
               </td>
           </tr>
       } 
       }
   </table>
    </div>

<script type="text/javascript">

    function getAttachment(url) {
        var width = screen.availWidth * 0.95;
        var top = screen.availWidth * 0.05;
        var left = screen.availWidth * 0.05;
        var height = screen.availHeight * 0.80;
        var m = window.open(url, "", "width=" + width + "px, height=" + height + "px, top=" + top + "px, left=" + left + "px");
    }

    function AddFormAttachment() {
        var formID = $("#hID").val();
        var FormType = '@ViewContext.RouteData.Values["action"]';
        var url = '@Url.Action("FormAttachement", "Form")' + "?FormID=" + formID + "&&FormType=" + FormType;
        window.top.winObj = window;
        window.top.refresh = FormAttachmentCallBack;
        window.top.oDG = $.dialog({
            lock: true,
            background: '#FFF',
            opacity: 0.5,
            id: 'esDialog',
            title: "附件选择",
            titleAlign: 'left',
            content: "url:" + url,
            width: 400,
            height: 250,
            btnBar: false,
            lockScroll: true
        });
    }
    function DelFormAttachment() {
        $(".ckAttachment:checked").each(function () {
            var FormAttachmentID = $(this).val();
            var url = '@Url.Action("DeleteFormAttachement","Form")' + "?FormAttachmentID=" + FormAttachmentID;
            var tag = this;
            $.post(url, function (data) {
                $(tag).parent().parent().remove();
            });
        });
    }
    function FormAttachmentCallBack(id, name, attachment, remark, AttachmentType) {
        var url = '@Url.Action("GetFormAttachementFile","Form")' + "?FileName=" + attachment;
        if (AttachmentType == 2)
            url = attachment;
        var str = '';
        str = str + '<tr>';
        str = str + '       <td>';
        str = str + '  <input  class="ckAttachment" dataRemark="' + remark + '"  dataID="' + id + '" dataName="' + name + '" dataAttachment="' + attachment + '" name="ck" type="checkbox" value="' + id + '" />';
        str = str + '</td>';
        str = str + '<td>';
        str = str + ' <p> <a href="' + url + '" target="_blank">' + name + '</a> </p>';
        str = str + '</td>'
        str = str + '</tr>'
        $(str).appendTo("#tbFormAttachment");
    }

</script>